{% extends "base.html" %}

{% block content %}
<div class="container-fluid">
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="mb-0">
                <i class="fas fa-history me-2"></i>{{ device.name }} - 历史水质数据
            </h5>
            <a href="{{ url_for('water.water_index') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>时间</th>
                            <th>pH值</th>
                            <th>浊度 (NTU)</th>
                            <th>溶解氧 (mg/L)</th>
                            <th>电导率 (μS/cm)</th>
                            <th>温度 (℃)</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for record in records %}
                        <tr>
                            <td>{{ record.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                            <td>{{ "%.2f"|format(record.ph) }}</td>
                            <td>{{ "%.2f"|format(record.turbidity) }}</td>
                            <td>{{ "%.2f"|format(record.dissolved_oxygen) }}</td>
                            <td>{{ "%.2f"|format(record.conductivity) }}</td>
                            <td>{{ "%.1f"|format(record.temperature) }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            {% if pagination and pagination.pages > 1 %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    <li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('water.water_history', device_id=device.id, page=pagination.prev_num) if pagination.has_prev else '#' }}">
                            <i class="fas fa-chevron-left"></i>
                        </a>
                    </li>
                    {% for page in pagination.iter_pages() %}
                        {% if page %}
                            <li class="page-item {% if page == pagination.page %}active{% endif %}">
                                <a class="page-link" href="{{ url_for('water.water_history', device_id=device.id, page=page) }}">{{ page }}</a>
                            </li>
                        {% else %}
                            <li class="page-item disabled">
                                <span class="page-link">...</span>
                            </li>
                        {% endif %}
                    {% endfor %}
                    <li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('water.water_history', device_id=device.id, page=pagination.next_num) if pagination.has_next else '#' }}">
                            <i class="fas fa-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 